package com.xinghai.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.xinghai.common.exception.ServiceException;
import java.io.IOException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import com.xinghai.common.constant.GenConstants;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xinghai.common.annotation.Log;
import com.xinghai.common.core.controller.BaseController;
import com.xinghai.common.core.domain.AjaxResult;
import com.xinghai.common.enums.BusinessType;
import com.xinghai.system.domain.QdShopOrder;
import com.xinghai.system.service.IQdShopOrderService;
import com.xinghai.common.utils.poi.ExcelUtil;
import org.springframework.web.multipart.MultipartFile;
import com.xinghai.common.core.page.TableDataInfo;

/**
 * 订单模块Controller
 *
 * @author xinghai
 * @date 2025-01-26
 */
@RestController
@RequestMapping("/system/shopOrder")
public class QdShopOrderController extends BaseController
{
    @Autowired
    private IQdShopOrderService qdShopOrderService;

    /**
     * 查询订单模块列表
     */
    @PreAuthorize("@ss.hasPermi('system:shopOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(QdShopOrder qdShopOrder)
    {
        startPage();
        List<QdShopOrder> list = qdShopOrderService.list(qdShopOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单模块列表
     */
    @PreAuthorize("@ss.hasPermi('system:shopOrder:export')")
    @Log(title = "订单模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QdShopOrder qdShopOrder)
    {
        List<QdShopOrder> list = qdShopOrderService.list(qdShopOrder);
        ExcelUtil<QdShopOrder> util = new ExcelUtil<QdShopOrder>(QdShopOrder.class);
        util.exportExcel(response, list, "订单模块数据");
    }

    /**
     * 获取订单模块详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:shopOrder:query')")
    @GetMapping("/getInfo")
    public AjaxResult getInfo(Long id)
    {
        return success(qdShopOrderService.getById(id));
    }

    /**
     * 新增订单模块
     */
    @PreAuthorize("@ss.hasPermi('system:shopOrder:add')")
    @Log(title = "订单模块", businessType = BusinessType.INSERT)
    @PostMapping("/insert")
    public AjaxResult add(@RequestBody QdShopOrder qdShopOrder)
    {
        return toAjax(qdShopOrderService.save(qdShopOrder));
    }

    /**
     * 修改订单模块
     */
    @PreAuthorize("@ss.hasPermi('system:shopOrder:edit')")
    @Log(title = "订单模块", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult update(@RequestBody QdShopOrder qdShopOrder)
    {
        return toAjax(qdShopOrderService.updateById(qdShopOrder));
    }

    /**
     * 删除订单模块
     */
    @PreAuthorize("@ss.hasPermi('system:shopOrder:remove')")
    @Log(title = "订单模块", businessType = BusinessType.DELETE)
	@PostMapping("/delete")
    public AjaxResult delete(Long id)
    {
        return toAjax(qdShopOrderService.delete(id,GenConstants.DELETE_FLAG_TRUE));
    }


    /**
     * 批量删除订单模块
     */
    @PreAuthorize("@ss.hasPermi('system:shopOrder:remove')")
    @Log(title = "订单模块", businessType = BusinessType.DELETE)
    @PostMapping("/deleteBatch")
    public AjaxResult deleteBatch(Long[] ids)
    {
        return toAjax(qdShopOrderService.deleteBatch(ids,GenConstants.DELETE_FLAG_TRUE));
    }

    /**
     * 导入订单模块模板
     */
    @PreAuthorize("@ss.hasPermi('system:shopOrder:import')")
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<QdShopOrder> util = new ExcelUtil<QdShopOrder>(QdShopOrder.class);
        util.importTemplateExcel(response, "订单模块数据模板");
    }


    /**
     * 导入订单模块
     */
    @Log(title = "订单模块管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:shopOrder:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file)
    {
        ExcelUtil<QdShopOrder> util = new ExcelUtil<QdShopOrder>(QdShopOrder.class);
        List<QdShopOrder> qdShopOrderList = null;
        try {
            qdShopOrderList = util.importExcel(file.getInputStream());
        } catch (IOException e) {
            throw new ServiceException("导入数据失败");
        }
        return success(qdShopOrderService.importData(qdShopOrderList));
    }
}
